package com.heima.article.listen;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class PublishArticleListen {
    @Autowired
    ApArticleService apArticleService;

    @RabbitListener(queuesToDeclare = @Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE))
    public  void listenPublishArticle(String newsId){
    log.info("接受文章发布消息 消息内容为：{}   接受消息的时间：{}",newsId, LocalDateTime.now().toString());
    //调用发布文章方法
    apArticleService.publishArticle(Integer.valueOf(newsId));
    log.info("发布文章 结束  ==========");

    }
}
